package com.qcby.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.qcby.dao.MessageDao;
import com.qcby.entity.Message;
import com.qcby.entity.PageResult;
import com.qcby.entity.Student;
import com.qcby.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MessageServiceImpl implements MessageService {
    @Autowired
    private MessageDao messageDao;
    @Override
    public List<Message> findAllMessage() {
        return messageDao.findAllMessage();
    }

    @Override
    public List<Message> findSystemAllMessage(Message msg) {
        PageHelper.startPage(msg.getPage(), msg.getPageSize());
        List<Message> page1 =  messageDao.findSystemAllMessage();
        Page<Message> page2 = (Page<Message>) page1;
        PageResult<Message> pageResult = new PageResult<>(page2.getTotal(),page2.getResult());
        List<Message> messageList= (List<Message>) pageResult.getRows();
        return page1;
    }

    @Override
    public void addMessage(Message message) {
        message.setCreateTime(new java.util.Date());
        messageDao.addMessage(message);
    }

    @Override
    public List<Message> findAIMessages(Message checkMsg) {
        return messageDao.findAIMessages(checkMsg);
    }

    @Override
    public List<Message> findSingleMessage(Message checkMsg) {
        return messageDao.findSingleMessage(checkMsg);
    }

    @Override
    public List<Message> findMessageByStudentName(Student student) {
        return messageDao.findMessageByStudentName(student);
    }
    @Override
    public List<Message> SearchMessage(String name) {
        return messageDao.SearchMessage(name);
    }

    @Override
    public List<Message> SearchMessageToStudent(String name) {
        return messageDao.SearchMessageToStudent(name);
    }

}
